package com.ruoyi.web.controller.riskAssessment;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.riskAssessment.domain.RiskLedger;
import com.ruoyi.riskAssessment.dto.RiskIdentifyEvaluationDto;
import com.ruoyi.riskAssessment.dto.RiskLedgerDto;
import com.ruoyi.riskAssessment.service.IRiskLedgerService;
import com.ruoyi.riskAssessment.vo.RiskIdentifyEvaluationVo;
import com.ruoyi.riskAssessment.vo.RiskLedgerVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 危险源-风险台账Controller
 *
 * @author lth
 * @date 2023-12-15
 */
@RestController
@RequestMapping("/riskAssessment/ledger")
public class RiskLedgerController extends BaseController
{
    @Autowired
    private IRiskLedgerService riskLedgerService;

    /**
     * 查询危险源-风险台账列表
     */
    @PreAuthorize("@ss.hasPermi('riskAssessment:ledger:list')")
    @GetMapping("/list")
    public TableDataInfo list(RiskLedger riskLedger)
    {
        startPage();
        List<RiskLedger> list = riskLedgerService.selectRiskLedgerList(riskLedger);
        return getDataTable(list);
    }

    /**
     * 导出危险源-风险台账列表
     */
    @PreAuthorize("@ss.hasPermi('riskAssessment:ledger:export')")
    @Log(title = "危险源-风险台账", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RiskLedger riskLedger)
    {
        List<RiskLedger> list = riskLedgerService.selectRiskLedgerList(riskLedger);
        ExcelUtil<RiskLedger> util = new ExcelUtil<RiskLedger>(RiskLedger.class);
        util.exportExcel(response, list, "危险源-风险台账数据");
    }

    /**
     * 获取危险源-风险台账详细信息
     */
    @PreAuthorize("@ss.hasPermi('riskAssessment:ledger:query')")
    @GetMapping(value = "/{riskLedgerId}")
    public AjaxResult getInfo(@PathVariable("riskLedgerId") String riskLedgerId)
    {
        return success(riskLedgerService.selectRiskLedgerByRiskLedgerId(riskLedgerId));
    }

    /**
     * 新增危险源-风险台账
     */
    @PreAuthorize("@ss.hasPermi('riskAssessment:ledger:add')")
    @Log(title = "危险源-风险台账", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RiskLedger riskLedger)
    {
        return toAjax(riskLedgerService.insertRiskLedger(riskLedger));
    }

    /**
     * 修改危险源-风险台账
     */
    @PreAuthorize("@ss.hasPermi('riskAssessment:ledger:edit')")
    @Log(title = "危险源-风险台账", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RiskLedger riskLedger)
    {
        return toAjax(riskLedgerService.updateRiskLedger(riskLedger));
    }

    /**
     * 删除危险源-风险台账
     */
    @PreAuthorize("@ss.hasPermi('riskAssessment:ledger:remove')")
    @Log(title = "危险源-风险台账", businessType = BusinessType.DELETE)
	@DeleteMapping("/{riskLedgerIds}")
    public AjaxResult remove(@PathVariable String[] riskLedgerIds)
    {
        return toAjax(riskLedgerService.deleteRiskLedgerByRiskLedgerIds(riskLedgerIds));
    }


    /** 矿台总账列表
    * @Author lth
    * @Description //TODO
    * @Date 16:19 2024/1/4
    * @Param
    * @return
     **/
    @PreAuthorize("@ss.hasPermi('riskAssessment:ledger:query')")
    @GetMapping("/ledgerList")
    public TableDataInfo ledgerList(RiskLedgerVo vo)
    {
        PageInfo<RiskLedgerDto> list = riskLedgerService.ledgerList(vo);
        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(HttpStatus.SUCCESS);
        rspData.setMsg("查询成功");
        rspData.setRows(list.getList());
        rspData.setTotal(list.getTotal());
        return rspData;
    }

    /**     个人台账列表
    * @Author lth
    * @Description //TODO
    * @Date 17:35 2024/1/4
    * @Param
    * @return
     **/
    @PreAuthorize("@ss.hasPermi('riskAssessment:ledger:query')")
    @GetMapping("/personLedgerList")
    public TableDataInfo personLedgerList(RiskLedgerVo vo)
    {
//        PageHelper.startPage(vo.getPageNum(),vo.getPageSize());
//        List<RiskLedgerDto> list = riskLedgerService.personLedgerList(vo);
//        return getDataTable(list);
        PageInfo<RiskLedgerDto> list = riskLedgerService.personLedgerList(vo);

        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(HttpStatus.SUCCESS);
        rspData.setMsg("查询成功");
        rspData.setRows(list.getList());
        rspData.setTotal(list.getTotal());
        return rspData;
    }

}
